package com.changou.controller;

import com.changou.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@Controller
@RequestMapping("/test")
public class ThController {


    @RequestMapping("/hello")
    public String hello(Model model){
        model.addAttribute("name","Hello Thymeleaf");
        //相当于后端查询list集合
        List<User> users = new ArrayList<User>();
        users.add(new User(1,"张三","上海1"));
        users.add(new User(2,"李四","北京"));
        users.add(new User(3,"王五","武汉"));
        model.addAttribute("users",users);

        Map<String,Object> dataMap = new HashMap<String,Object>();
        dataMap.put("No","123");
        dataMap.put("address","北京");
        model.addAttribute("dataMap",dataMap);

        //存储一个数组
        String[] names = {"张三","李四1","王五"};
        model.addAttribute("names",names);

        model.addAttribute("now",new Date());

        model.addAttribute("age",17);


        return "demo1";
    }

    @RequestMapping("/add")
    public String add(@RequestParam("name") String name){
        System.out.println(name);
        return "demo1";
    }




}
